from django.shortcuts import render
from strategies.strategies import runStrategie

# Create your views here.
def strategiesTest(request):

    info = {}
    result = []
    info["results"] = ""

    code = request.GET.get('code', '')
    if code == None or code == "":
        return render(request,"strategies_test.html", info)


    # 定期定额定投策略
    test1 = runStrategie("fixed_investment", code, 22, 1000, 2500, 2500, 1)
    result.append(["定期定额定投策略", test1])

    # 历史均线定投策略
    test2 = runStrategie("move_average", code, 22, 1000, 2500, 2500, 1)
    result.append(["历史均线定投策略", test2])

    # 年均线定投策略
    test3 = runStrategie("move_average", code, 22, 1000, 2500, 250, 1)
    result.append(["年均线定投策略", test3])

    # 半年均线定投策略
    test4 = runStrategie("move_average", code, 22, 1000, 2500, 125, 1)
    result.append(["半年均线定投策略", test4])

    # 月均线定投策略
    test5 = runStrategie("move_average", code, 22, 1000, 2500, 22, 1)
    result.append(["月均线定投策略", test5])

    result.sort(key = lambda x:x[1]['income_rate'])

    info["results"] = result
    return render(request,"strategies_test.html", info)